package cn.memorynine.consumer.config;

import cn.memorynine.consumer.filter.CorsFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

/**
 * 过滤器配置
 * @author 王加雷
 */
@Configuration
public class FilterConfig {
    /**
     * 初始化跨域过滤器
     * @return
     */
    @Bean
    @Order(1)
    public FilterRegistrationBean corsFilterRegistration() {
        //新建过滤器注册类
        FilterRegistrationBean registration = new FilterRegistrationBean();
        // 添加我们写好的过滤器
        registration.setFilter( new CorsFilter());
        //过滤所有路径-
        registration.addUrlPatterns("/*");

        return registration;
    }

}
